package com.hj.dapp.business.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hj.dapp.business.role.model.Role;
import com.hj.dapp.business.user.model.User;
import com.hj.dapp.business.user.service.UserService;
import com.hj.dapp.business.user.vo.RoleBind;
import com.hj.dapp.business.user.vo.UserInfoVO;
import com.hj.dapp.common.request.PageRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.enums.ParameterStyle;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;

/**
 * @author 胡奥程
 * @version 1.0
 * @date 2023/12/29
 */
@Tag(name = "UserController", description = "用户控制器接口")
@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/logout")
    public void logout(Principal principal) {

    }
    @GetMapping("/getUser/{userId}")
    public User getUser(@PathVariable("userId") String userId) {
        return userService.getUser(userId);
    }
    @GetMapping("/userInfo")
    public UserInfoVO userInfo(Principal principal) {
        return  userService.userInfo(principal);
    }
    @Operation(summary = "获取用户列表")
    @GetMapping("/getUserList")
    public List<User> getUserList() {
        return userService.getUserList();
    }

    @Operation(summary = "注册用户", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
            description = "用户信息",
            required = true
    ))
    @PutMapping("/registerUser")
    public void registerUser(@RequestBody User user, Principal principal) {
        userService.registerUser(user, principal);
    }

    @Operation(summary = "校验用户名唯一性", parameters = {
            @Parameter(name = "username", description = "用户名", required = true)
    })
    @GetMapping("/validateUserName/{username}")
    public void validateUserName(@PathVariable("username") String username) {
        userService.validateUserName(username);
    }

    @Operation(summary = "删除用户",parameters = @Parameter(
            style = ParameterStyle.SIMPLE,
            in = ParameterIn.PATH,
            name = "userName",
            description = "用户名"
    ))

    @DeleteMapping("/deleteUser/{userName}")
    public void deleteUser(@PathVariable("userName") String userName,Principal principal) {
        userService.deleteUser(userName,principal);
    }

    @Operation(summary = "编辑用户", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
            description = "用户信息",
            required = true
    ))
    @PostMapping("/editUser")
    public void editUser(@RequestBody User user, Principal principal) {

        userService.editUser(user, principal);
    }
    @Operation(summary = "用户分页列表", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
            description = "用户分页参数",
            required = true
    ))
    @PostMapping("/pageUser")
    public IPage<User> pageUser(@RequestBody PageRequest<User> request) {
        return userService.pageUser(request);
    }

    @GetMapping("/getRoleList/{userId}")
    public List<Role> getRoleList(@PathVariable("userId") Long userId) {
       return userService.getRoleList(userId);
    }
    @PostMapping("/bindRoleRel")
    public void bindRoleRel(@RequestBody RoleBind roleBind) {
        userService.bindRoleRel(roleBind);
    }
    @GetMapping("/getDesignerList")
    public List<User> getDesignerList() {
        return userService.getDesignerList();
    }
    @GetMapping("/getSupervisorList")
    public List<User> getSupervisorList() {
        return userService.getSupervisorList();
    }
    @GetMapping("/getReviewerList")
    public List<User> getReviewerList() {
        return userService.getReviewerList();
    }

}
